﻿using System.Linq;
using NUnit.Framework;
using Framework.Extensions;

namespace Framework.UnitTest.Extensions
{
    [TestFixture]
    public class ObjectExtensionsFixture
    {
        [Test]
        public void ChainReturnsSuccessiveElementsBasedOnASelectorMethod()
        {
            var thirdElement = new ObjectTestData();
            var secondElement = new ObjectTestData {NextElement = thirdElement};
            var firstElement = new ObjectTestData {NextElement = secondElement};

            var elementChain = firstElement
                .Chain(element => element.NextElement)
                .ToList();

            Assert.AreEqual(3, elementChain.Count);
            Assert.AreSame(firstElement, elementChain.ElementAt(0));
            Assert.AreSame(secondElement, elementChain.ElementAt(1));
            Assert.AreSame(thirdElement, elementChain.ElementAt(2));
        }
    }

    public class ObjectTestData
    {
        public ObjectTestData NextElement { get; set; }
    }
}